package com.cheng.im.gateway.protobuilder;

import com.cheng.im.common.constants.ProtoInstants;
import com.cheng.im.common.bean.msg.ProtoMsgV1;
import org.springframework.stereotype.Service;

@Service("LoginResponseBuilder")
public class LoginResponseBuilder
{

    /**
     * 登录应答 应答消息protobuf
     */
    public ProtoMsgV1.Message loginResponse(
            ProtoInstants.ResultCodeEnum en, long seqId, String sessionId)
    {
        ProtoMsgV1.Message.Builder mb = ProtoMsgV1.Message.newBuilder()
                .setType(ProtoMsgV1.HeadType.LOGIN_RESPONSE)  //设置消息类型
                .setSequence(seqId)
                .setSessionId(sessionId);  //设置应答流水，与请求对应

        ProtoMsgV1.LoginResponse.Builder b = ProtoMsgV1.LoginResponse.newBuilder()
                .setCode(en.getCode())
                .setInfo(en.getDesc())
                .setExpose(1);

        mb.setLoginResponse(b.build());
        return mb.build();
    }


}
